package org.pitest.ant.util;

import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.resources.FileResource;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Aidan Morgan
 */
public class PathUtils {
  /**
   * Helper method that will take in a {@see Path} instance and convert it into a corresponding
   * {@see List} of {@see FileResource} entries which represent all of the files in the provided {@see Path}.
   *
   * @param p the {@see Path} to convert.
   * @return a {@see List} of all {@see FileResource}s that are in the provided {@see Path}.
   */
  public static List<File> convertPath(Path p) {
    Iterator it = p.iterator();

    List<File> resources = new ArrayList<File>();

    while (it.hasNext()) {
      FileResource res = (FileResource) it.next();

      resources.add(res.getFile());
    }

    return resources;
  }
}
